// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarCarouselReq;
import com.liuxinlong.modules.chimi.service.BarCarouselService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.BarCarousel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛轮播管理控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-11-09
 */
@RestController
@RequestMapping("/carousel")
public class BarCarouselController {

	@Autowired
	private BarCarouselService barCarouselService;

	/**
	 * 分页查询轮播配置信息
	 * 
	 * @param req 请求信息
	 * @return 轮播配置信息列表
	 */
	@PostMapping("page")
	public BaseResp pageCarouselList(@RequestBody QueryBaseReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		List<Map<String,Object>> dataList = barCarouselService.pageCarousel(queryParam);
		int total = barCarouselService.getCarouselCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询轮播信息成功");
		return resp;
	}

	/**
	 * 新增轮播
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("add")
	@LogAnnotation(value ="新增轮播",business = LogBusinessConstants.BAR_CAROUSEL,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp addCarousel(@RequestBody UpdateBarCarouselReq req) {
		BarCarousel barCarousel = new BarCarousel();
		barCarousel.setTitle(req.getTitle());
		barCarousel.setShowIndex(req.getShowIndex());
		barCarousel.setPicture(req.getPicture());
		barCarousel.setPictureMobile(req.getPictureMobile());
		barCarousel.setRelation(req.getRelation());
		barCarousel.setStartTime(req.getStartTime());
		barCarousel.setEndTime(req.getEndTime());
		barCarousel.setRemark(req.getRemark());
		barCarouselService.addCarousel(barCarousel);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("新增轮播成功");
		return resp;
	}

	/**
	 * 修改轮播信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改轮播信息",business = LogBusinessConstants.BAR_CAROUSEL,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updateCarousel(@RequestBody UpdateBarCarouselReq req) {
		BarCarousel barCarousel = new BarCarousel();
		barCarousel.setId(req.getId());
		barCarousel.setTitle(req.getTitle());
		barCarousel.setShowIndex(req.getShowIndex());
		barCarousel.setPicture(req.getPicture());
		barCarousel.setPictureMobile(req.getPictureMobile());
		barCarousel.setRelation(req.getRelation());
		barCarousel.setStartTime(req.getStartTime());
		barCarousel.setEndTime(req.getEndTime());
		barCarousel.setRemark(req.getRemark());
		barCarouselService.updateCarousel(barCarousel);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改轮播信息成功");
		return resp;
	}

	/**
	 * 删除轮播信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("delete")
	@LogAnnotation(value ="删除轮播信息",business = LogBusinessConstants.BAR_CAROUSEL,operateType = LogOperateConstants.OPERATE_DELETE)
	public BaseResp deleteCarousel(@RequestBody BaseDeleteReq req) {
		barCarouselService.deleteCarousel(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("删除轮播信息成功");
		return resp;
	}

	/**
	 * 修改轮播状态
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("status/update")
	@LogAnnotation(value ="修改轮播状态",business = LogBusinessConstants.BAR_CAROUSEL,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updateCarouselStatus(@RequestBody BaseDeleteReq req) {
		barCarouselService.updateCarouselStatus(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改轮播状态成功");
		return resp;
	}

}
